package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.CameraEntity;
import io.renren.modules.generator.service.CameraService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 摄像头信息
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-05-23 11:21:35
 */
@RestController
@RequestMapping("camera")
public class CameraController {
	@Autowired
	private CameraService cameraService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("camera:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<CameraEntity> cameraList = cameraService.queryList(query);
		int total = cameraService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(cameraList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{cameraId}")
	@RequiresPermissions("camera:info")
	public R info(@PathVariable("cameraId") Integer cameraId){
		CameraEntity camera = cameraService.queryObject(cameraId);
		
		return R.ok().put("camera", camera);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("camera:save")
	public R save(@RequestBody CameraEntity camera){
		cameraService.save(camera);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("camera:update")
	public R update(@RequestBody CameraEntity camera){
		cameraService.update(camera);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("camera:delete")
	public R delete(@RequestBody Integer[] cameraIds){
		cameraService.deleteBatch(cameraIds);
		
		return R.ok();
	}

	@RequestMapping("/timelist")
	@RequiresPermissions("camera:list")
	public R timelist(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);

		List<CameraEntity> alivepriceList = cameraService.timeList(query);
		int total = cameraService.timeTotal(query);

		PageUtils pageUtil = new PageUtils(alivepriceList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}
	
}
